﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MedReg
{
    public partial class RecordTypeIn : IEquatable<RecordTypeIn>
    {
        public void ImportList(List<Classes.RecordTypeIn> rtiList)
        {
            var mdb = new MedregDBDataContext();
            var ListRTI = new List<RecordTypeIn>();
            foreach (var rti in rtiList)
            {
                RecordTypeIn rti1 = new RecordTypeIn() { ID = rti.ID, Name = rti.Name };
                RecordTypeIn query;

                if (mdb.RecordTypeIn.LongCount() == 0)
                {
                    mdb.RecordTypeIn.InsertOnSubmit(rti1);
                }
                else
                {
                    try
                    {
                        query = mdb.RecordTypeIn.Single(l => l.ID == rti1.ID);
                        query.Name = rti1.Name;

                    }
                    catch (ArgumentNullException e)
                    {
                    }
                    catch (InvalidOperationException e)
                    {

                        if (!ListRTI.Contains(rti1))
                        {
                            mdb.RecordTypeIn.InsertOnSubmit(rti1);
                            ListRTI.Add(rti1);
                        }
                    }
                }
            }
            mdb.SubmitChanges();
        }
        public bool Equals(RecordTypeIn other)
        {
            var i = this.ID.Equals(other.ID);
            var j = this.Name.Equals(other.Name);
            if (i & j)
            {
                return true;
            }
            return false;
        }
    }
}
